<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "psacar_carinfo.php" ?>
<?php include "psacar_car_imageinfo.php" ?>
<?php include "psacar_userinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php
// Create page object
$psacar_car_edit = new cpsacar_car_edit();
$Page = & $psacar_car_edit;

// Page init
$psacar_car_edit->Page_Init();

// Page main
$psacar_car_edit->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
    <!--

    // Create page object
    var psacar_car_edit = new ew_Page("psacar_car_edit");

    // page properties
    psacar_car_edit.PageID = "edit"; // page ID
    psacar_car_edit.FormID = "fpsacar_caredit"; // form ID
    var EW_PAGE_ID = psacar_car_edit.PageID; // for backward compatibility

    // extend page with ValidateForm function
    psacar_car_edit.ValidateForm = function(fobj) {
        ew_PostAutoSuggest(fobj);
        if (!this.ValidateRequired)
            return true; // ignore validation
        if (fobj.a_confirm && fobj.a_confirm.value == "F")
            return true;
        var i, elm, aelm, infix;
        var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
        for (i=0; i<rowcnt; i++) {
            infix = (fobj.key_count) ? String(i+1) : "";
            elm = fobj.elements["x" + infix + "_dealer_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->dealer_id->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_model_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->model_id->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_year"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->year->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_external_color_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->external_color_id->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_internal_color_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->internal_color_id->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_category_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->category_id->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_type_id"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->type_id->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_year"];
            if (elm && !ew_CheckNumber(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->price->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_price"];
            if (elm && !ew_CheckNumber(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->price->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_quality"];
            if (elm && !ew_CheckInteger(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->quality->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_post_date"];
            if (elm && !ew_CheckDate(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->post_date->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_expiration_date"];
            if (elm && !ew_HasValue(elm))
                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->expiration_date->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_expiration_date"];
            if (elm && !ew_CheckDate(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->expiration_date->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_image"];
            if (elm && !ew_CheckFileType(elm.value))
                return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));
//            elm = fobj.elements["x" + infix + "_vehicle_id_number"];
//            if (elm && !ew_HasValue(elm))
//                return ew_OnError(this, elm, ewLanguage.Phrase("EnterRequiredField") + " - <?php echo ew_JsEncode2($psacar_car->vehicle_id_number->FldCaption()) ?>");
            elm = fobj.elements["x" + infix + "_duration"];
            if (elm && !ew_CheckInteger(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->duration->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_create_date"];
            if (elm && !ew_CheckDate(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->create_date->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_end_date"];
            if (elm && !ew_CheckDate(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->end_date->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_created_date"];
            if (elm && !ew_CheckDate(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->created_date->FldErrMsg()) ?>");
            elm = fobj.elements["x" + infix + "_modified_date"];
            if (elm && !ew_CheckDate(elm.value))
                return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_car->modified_date->FldErrMsg()) ?>");

            // Call Form Custom Validate event
            if (!this.Form_CustomValidate(fobj)) return false;
        }
        return true;
    }

    // extend page with Form_CustomValidate function
    psacar_car_edit.Form_CustomValidate =  
        function(fobj) { // DO NOT CHANGE THIS LINE!

        // Your custom validation code here, return false if invalid. 
        return true;
    }
<?php if (EW_CLIENT_VALIDATE) { ?>
        psacar_car_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
        psacar_car_edit.ValidateRequired = false; // no JavaScript validation
<?php } ?>

    //-->
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    <!--
    _width_multiplier = 20;
    _height_multiplier = 60;
    var ew_DHTMLEditors = [];

    // update value from editor to textarea
    function ew_UpdateTextArea() {
        if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {			
            var inst;			
            for (inst in CKEDITOR.instances)
                CKEDITOR.instances[inst].updateElement();
        }
    }

    // update value from textarea to editor
    function ew_UpdateDHTMLEditor(name) {
        if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
            var inst = CKEDITOR.instances[name];		
            if (inst)
                inst.setData(inst.element.value);
        }
    }

    // focus editor
    function ew_FocusDHTMLEditor(name) {
        if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
            var inst = CKEDITOR.instances[name];	
            if (inst)
                inst.focus();
        }
    }

    //-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
    <!--

    // Write your client script here, no need to add script tags.
    // To include another .js script, use:
    // ew_ClientScriptInclude("my_javascript.js"); 
    //-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $psacar_car->TableCaption() ?><br><br>
        <a href="<?php echo $psacar_car->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
    echo ew_DebugMsg();
$psacar_car_edit->ShowMessage();
?>
<form name="fpsacar_caredit" id="fpsacar_caredit" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return psacar_car_edit.ValidateForm(this);">
    <p>
        <input type="hidden" name="a_table" id="a_table" value="psacar_car">
        <input type="hidden" name="a_edit" id="a_edit" value="U">
    <table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
                <div class="ewGridMiddlePanel">
                    <table cellspacing="0" class="ewTable">
                        <?php if ($psacar_car->id->Visible) { // id ?>
                            <tr<?php echo $psacar_car->id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->id->FldCaption() ?></td>
                                <td<?php echo $psacar_car->id->CellAttributes() ?>><span id="el_id">
                                        <div<?php echo $psacar_car->id->ViewAttributes() ?>><?php echo $psacar_car->id->EditValue ?></div><input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($psacar_car->id->CurrentValue) ?>">
                                    </span><?php echo $psacar_car->id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->dealer_id->Visible) { // dealer_id ?>
                            <tr<?php echo $psacar_car->dealer_id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->dealer_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->dealer_id->CellAttributes() ?>><span id="el_dealer_id">
                                        <select id="x_dealer_id" name="x_dealer_id" title="<?php echo $psacar_car->dealer_id->FldTitle() ?>"<?php echo $psacar_car->dealer_id->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->dealer_id->EditValue)) {
                                                $arwrk = $psacar_car->dealer_id->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->dealer_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->dealer_id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->model_id->Visible) { // model_id  ?>
                            <tr<?php echo $psacar_car->model_id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->model_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->model_id->CellAttributes() ?>><span id="el_model_id">
                                        <select id="x_model_id" name="x_model_id" title="<?php echo $psacar_car->model_id->FldTitle() ?>"<?php echo $psacar_car->model_id->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->model_id->EditValue)) {
                                                $arwrk = $psacar_car->model_id->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->model_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->model_id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->year->Visible) { // year  ?>
                            <tr<?php echo $psacar_car->year->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->year->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->year->CellAttributes() ?>><span id="el_year">
                                        <input type="text" name="x_year" id="x_year" title="<?php echo $psacar_car->year->FldTitle() ?>" size="30" value="<?php echo $psacar_car->year->EditValue ?>"<?php echo $psacar_car->year->EditAttributes() ?>>
                                    </span><?php echo $psacar_car->year->CustomMsg ?></td>
                            </tr>
                        <?php } ?>   
                        <?php if ($psacar_car->external_color_id->Visible) { // internal_color_id  ?>
                            <tr<?php echo $psacar_car->external_color_id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->external_color_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->external_color_id->CellAttributes() ?>><span id="el_internal_color_id">
                                        <select id="x_external_color_id" name="x_external_color_id" title="<?php echo $psacar_car->external_color_id->FldTitle() ?>"<?php echo $psacar_car->external_color_id->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->external_color_id->EditValue)) {
                                                $arwrk = $psacar_car->external_color_id->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->external_color_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->internal_color_id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->internal_color_id->Visible) { // internal_color_id  ?>
                            <tr<?php echo $psacar_car->internal_color_id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->internal_color_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->internal_color_id->CellAttributes() ?>><span id="el_internal_color_id">
                                        <select id="x_internal_color_id" name="x_internal_color_id" title="<?php echo $psacar_car->internal_color_id->FldTitle() ?>"<?php echo $psacar_car->internal_color_id->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->internal_color_id->EditValue)) {
                                                $arwrk = $psacar_car->internal_color_id->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->internal_color_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->internal_color_id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>        
                        <?php if ($psacar_car->category_id->Visible) { // category_id  ?>
                            <tr<?php echo $psacar_car->category_id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->category_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->category_id->CellAttributes() ?>><span id="el_category_id">
                                        <select id="x_category_id" name="x_category_id" title="<?php echo $psacar_car->category_id->FldTitle() ?>"<?php echo $psacar_car->category_id->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->category_id->EditValue)) {
                                                $arwrk = $psacar_car->category_id->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->category_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->category_id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>        
                        <?php if ($psacar_car->type_id->Visible) { // type_id ?>
                            <tr<?php echo $psacar_car->type_id->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->type_id->FldCaption() ?><?php echo $Language->Phrase("FieldRequiredIndicator") ?></td>
                                <td<?php echo $psacar_car->type_id->CellAttributes() ?>><span id="el_type_id">
                                        <select id="x_type_id" name="x_type_id" title="<?php echo $psacar_car->type_id->FldTitle() ?>"<?php echo $psacar_car->type_id->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->type_id->EditValue)) {
                                                $arwrk = $psacar_car->type_id->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->type_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->type_id->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->vehicle_id_number->Visible) { // vehicle_id_number  ?>
                            <tr<?php echo $psacar_car->vehicle_id_number->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->vehicle_id_number->FldCaption() ?></td>
                                <td<?php echo $psacar_car->vehicle_id_number->CellAttributes() ?>><span id="el_vehicle_id_number">
                                        <input type="text" name="x_vehicle_id_number" id="x_vehicle_id_number" title="<?php echo $psacar_car->vehicle_id_number->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $psacar_car->vehicle_id_number->EditValue ?>"<?php echo $psacar_car->vehicle_id_number->EditAttributes() ?>>
                                    </span><?php echo $psacar_car->vehicle_id_number->CustomMsg ?></td>
                            </tr>
                        <?php } ?>        
                        <?php if ($psacar_car->description->Visible) { // description  ?>
                            <tr<?php echo $psacar_car->description->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->description->FldCaption() ?></td>
                                <td<?php echo $psacar_car->description->CellAttributes() ?>><span id="el_description">
                                        <textarea name="x_description" id="x_description" title="<?php echo $psacar_car->description->FldTitle() ?>" cols="40" rows="10"<?php echo $psacar_car->description->EditAttributes() ?>><?php echo $psacar_car->description->EditValue ?></textarea>
                                        <script type="text/javascript">
                                            <!--
                                            ew_DHTMLEditors.push(new ew_DHTMLEditor("x_description", function() {
                                                var oCKeditor = CKEDITOR.replace('x_description', { width: 40*_width_multiplier, height: 10*_height_multiplier, autoUpdateElement: false, baseHref: 'ckeditor/'});
                                                this.active = true;
                                            }));
                                            -->
                                        </script>
                                    </span><?php echo $psacar_car->description->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php
                        if ($psacar_car->price->Visible) { // price 
                            ?>
                            <tr<?php echo $psacar_car->price->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->price->FldCaption() ?></td>
                                <td<?php echo $psacar_car->price->CellAttributes() ?>>
                                    <span id="el_price">
                                        <input type="text" name="x_price" id="x_price" title="<?php echo $psacar_car->price->FldTitle() ?>" size="30" value="<?php echo $psacar_car->price->EditValue ?>"<?php echo $psacar_car->price->EditAttributes() ?>>
                                    </span>
                                    <?php
                                    echo $psacar_car->price->CustomMsg
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                        ?>
                        <?php if ($psacar_car->quality->Visible) { // quality  ?>
                            <tr<?php echo $psacar_car->quality->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->quality->FldCaption() ?></td>
                                <td<?php echo $psacar_car->quality->CellAttributes() ?>>
                                    <span id="el_quality">
                                        <input type="text" name="x_quality" id="x_quality" value="<?php echo $psacar_car->quality->CurrentValue ?>">
                                    </span>
                                    <?php
                                    echo $psacar_car->quality->CustomMsg
                                    ?>
                                </td>
                            </tr>
                            <?php
                        }
                        ?>
                        <?php if ($psacar_car->transmission->Visible) { // transmission ?>
                            <tr<?php echo $psacar_car->transmission->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->transmission->FldCaption() ?></td>
                                <td<?php echo $psacar_car->transmission->CellAttributes() ?>><span id="el_transmission">
                                        <select id="x_transmission" name="x_transmission" title="<?php echo $psacar_car->transmission->FldTitle() ?>"<?php echo $psacar_car->transmission->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->transmission->EditValue)) {
                                                $arwrk = $psacar_car->transmission->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->transmission->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->transmission->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->drive_train->Visible) { // drive_train  ?>
                            <tr<?php echo $psacar_car->drive_train->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->drive_train->FldCaption() ?></td>
                                <td<?php echo $psacar_car->drive_train->CellAttributes() ?>><span id="el_drive_train">
                                        <select id="x_drive_train" name="x_drive_train" title="<?php echo $psacar_car->drive_train->FldTitle() ?>"<?php echo $psacar_car->drive_train->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->drive_train->EditValue)) {
                                                $arwrk = $psacar_car->drive_train->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->drive_train->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->drive_train->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->door_count->Visible) { // door_count ?>
                            <tr<?php echo $psacar_car->door_count->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->door_count->FldCaption() ?></td>
                                <td<?php echo $psacar_car->door_count->CellAttributes() ?>><span id="el_door_count">
                                        <select id="x_door_count" name="x_door_count" title="<?php echo $psacar_car->door_count->FldTitle() ?>"<?php echo $psacar_car->door_count->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->door_count->EditValue)) {
                                                $arwrk = $psacar_car->door_count->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->door_count->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->door_count->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->fuel->Visible) { // fuel ?>
                            <tr<?php echo $psacar_car->fuel->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->fuel->FldCaption() ?></td>
                                <td<?php echo $psacar_car->fuel->CellAttributes() ?>><span id="el_fuel">
                                        <div id="tp_x_fuel" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_fuel[]" id="x_fuel[]" title="<?php echo $psacar_car->fuel->FldTitle() ?>" value="{value}"<?php echo $psacar_car->fuel->EditAttributes() ?>></div>
                                        <div id="dsl_x_fuel" repeatcolumn="5">
                                            <?php
                                            $arwrk = $psacar_car->fuel->EditValue;
                                            if (is_array($arwrk)) {
                                                $armultiwrk = explode(",", strval($psacar_car->fuel->CurrentValue));
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = "";
                                                    for ($ari = 0; $ari < count($armultiwrk); $ari++) {
                                                        if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
                                                            $selwrk = " checked=\"checked\"";
                                                            if ($selwrk <> "")
                                                                $emptywrk = FALSE;
                                                            break;
                                                        }
                                                    }

                                                    // Note: No spacing within the LABEL tag
                                                    ?>
                                                    <?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
                                                    <label><input type="checkbox" name="x_fuel[]" id="x_fuel[]" title="<?php echo $psacar_car->fuel->FldTitle() ?>" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $psacar_car->fuel->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
                                                    <?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </div>
                                    </span><?php echo $psacar_car->fuel->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php  ?>
                        <?php  ?>
                        <?php  ?>
                        <?php  ?>
                        <?php
                        ?>        
                        <?php  ?>
                        <?php
                        
                        ?>
                        <?php  ?>
                        <?php
                        
                        ?>
                        <?php
                        
                        ?>
                        <?php if ($psacar_car->status->Visible) { // status  ?>
                            <tr<?php echo $psacar_car->status->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->status->FldCaption() ?></td>
                                <td<?php echo $psacar_car->status->CellAttributes() ?>><span id="el_status">
                                        <select id="x_status" name="x_status" title="<?php echo $psacar_car->status->FldTitle() ?>"<?php echo $psacar_car->status->EditAttributes() ?>>
                                            <?php
                                            if (is_array($psacar_car->status->EditValue)) {
                                                $arwrk = $psacar_car->status->EditValue;
                                                $rowswrk = count($arwrk);
                                                $emptywrk = TRUE;
                                                for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
                                                    $selwrk = (strval($psacar_car->status->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
                                                    if ($selwrk <> "")
                                                        $emptywrk = FALSE;
                                                    ?>
                                                    <option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
                                                        <?php echo $arwrk[$rowcntwrk][1] ?>
                                                    </option>
                                                    <?php
                                                }
                                            }
                                            ?>
                                        </select>
                                    </span><?php echo $psacar_car->status->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->code->Visible) { // code  ?>
                            <tr<?php echo $psacar_car->code->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->code->FldCaption() ?></td>
                                <td<?php echo $psacar_car->code->CellAttributes() ?>><span id="el_code">
                                        <input type="text" name="x_code" id="x_code" title="<?php echo $psacar_car->code->FldTitle() ?>" size="30" maxlength="255" value="<?php echo $psacar_car->code->EditValue ?>"<?php echo $psacar_car->code->EditAttributes() ?>>
                                    </span><?php echo $psacar_car->code->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->post_date->Visible) { // post_date  ?>
                            <tr<?php echo $psacar_car->post_date->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->post_date->FldCaption() ?></td>
                                <td<?php echo $psacar_car->post_date->CellAttributes() ?>><span id="el_post_date">
                                        <input type="text" name="x_post_date" id="x_post_date" title="<?php echo $psacar_car->post_date->FldTitle() ?>" value="<?php echo $psacar_car->post_date->EditValue ?>"<?php echo $psacar_car->post_date->EditAttributes() ?>>
                                        &nbsp;<img src="images/calendar.png" id="cal_x_post_date" name="cal_x_post_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
                                        <script type="text/javascript">
                                            Calendar.setup({
                                                inputField: "x_post_date", // input field id
                                                ifFormat: "%Y/%m/%d", // date format
                                                button: "cal_x_post_date" // button id
                                            });
                                        </script>
                                    </span><?php echo $psacar_car->post_date->CustomMsg ?></td>
                            </tr>
                        <?php } ?>
                        <?php if ($psacar_car->expiration_date->Visible) { // expiration_date  ?>
                            <tr<?php echo $psacar_car->expiration_date->RowAttributes ?>>
                                <td class="ewTableHeader"><?php echo $psacar_car->expiration_date->FldCaption() ?></td>
                                <td<?php echo $psacar_car->expiration_date->CellAttributes() ?>><span id="el_expiration_date">
                                        <input type="text" name="x_expiration_date" id="x_expiration_date" title="<?php echo $psacar_car->expiration_date->FldTitle() ?>" value="<?php echo $psacar_car->expiration_date->EditValue ?>"<?php echo $psacar_car->expiration_date->EditAttributes() ?>>
                                        &nbsp;<img src="images/calendar.png" id="cal_x_expiration_date" name="cal_x_expiration_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
                                        <script type="text/javascript">
                                            Calendar.setup({
                                                inputField: "x_expiration_date", // input field id
                                                ifFormat: "%Y/%m/%d", // date format
                                                button: "cal_x_expiration_date" // button id
                                            });
                                        </script>
                                    </span><?php echo $psacar_car->expiration_date->CustomMsg ?></td>
                            </tr>
                        <?php } ?>        

<?php 
if ($psacar_car->image_1->Visible) { // image     
?>
    <tr<?php echo $psacar_car->image_1->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_1->FldCaption() 
?>
        </td>
        <td<?php echo $psacar_car->image_1->CellAttributes() ?>>
            <span id="el_image_1">
                <div id="old_x_image_1">
                    <input type="hidden" name="x_id_image_1" id="x_id_image_1" value="<?php echo ew_HtmlEncode($psacar_car->id_image_1->CurrentValue) ?>">
<?php 
if ($psacar_car->image_1->HrefValue <> "" || $psacar_car->image_1->TooltipValue <> "") { 
?>
<?php 
    if (!empty($psacar_car->image_1->Upload->DbValue)) { 
?>
                    <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_1->UploadPath) . $psacar_car->image_1->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_1->ViewAttributes() ?>>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php 
    } 
?>
<?php 
} 
else {     
?>
<?php 
    if (!empty($psacar_car->image_1->Upload->DbValue)) {         
?>
        <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_1->UploadPath) . $psacar_car->image_1->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_1->ViewAttributes() ?>>
<?php 
?>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php     
    } 
?>
<?php 
} 
?>
                </div>
                <div id="new_x_image_1">
<?php 
                if (!empty($psacar_car->image_1->Upload->DbValue)) { 
?>
                    <label>
                        <input type="radio" name="a_image_1" id="a_image_1" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_1" id="a_image_1" value="2"><?php echo $Language->Phrase("Remove") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_1" id="a_image_1" value="3"><?php echo $Language->Phrase("Replace") ?><br>
                    </label>
<?php 
                $psacar_car->image_1->EditAttrs["onchange"] = "this.form.a_image_1[2].checked=true;" . @$psacar_car->image_1->EditAttrs["onchange"]; 
?>
<?php                 
                } 
                else { 
?>
                    <input type="hidden" name="a_image_1" id="a_image_1" value="3">
<?php                 
                } 
?>
                    <input type="file" name="x_image_1" id="x_image_1" title="<?php echo $psacar_car->image_1->FldTitle() ?>" size="30"<?php echo $psacar_car->image_1->EditAttributes() ?>>
                </div>
            </span>
<?php 
            echo $psacar_car->image_1->CustomMsg 
?>
        </td>
    </tr>
<?php } ?>
    
<?php 
if ($psacar_car->image_2->Visible) { // image     
?>
    <tr<?php echo $psacar_car->image_2->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_2->FldCaption() 
?>
        </td>
        <td<?php echo $psacar_car->image_2->CellAttributes() ?>>
            <span id="el_image_2">
                <div id="old_x_image_2">
                    <input type="hidden" name="x_id_image_2" id="x_id_image_2" value="<?php echo ew_HtmlEncode($psacar_car->id_image_2->CurrentValue) ?>">                    
<?php 
if ($psacar_car->image_2->HrefValue <> "" || $psacar_car->image_2->TooltipValue <> "") { 
?>
<?php 
    if (!empty($psacar_car->image_2->Upload->DbValue)) { 
?>
                    <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_2->UploadPath) . $psacar_car->image_2->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_2->ViewAttributes() ?>>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php 
    } 
?>
<?php 
} 
else {     
?>
<?php 
    if (!empty($psacar_car->image_2->Upload->DbValue)) {         
?>
        <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_2->UploadPath) . $psacar_car->image_2->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_2->ViewAttributes() ?>>
<?php 
?>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php     
    } 
?>
<?php 
} 
?>
                </div>
                <div id="new_x_image_2">
<?php 
                if (!empty($psacar_car->image_2->Upload->DbValue)) { 
?>
                    <label>
                        <input type="radio" name="a_image_2" id="a_image_2" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_2" id="a_image_2" value="2"><?php echo $Language->Phrase("Remove") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_2" id="a_image_2" value="3"><?php echo $Language->Phrase("Replace") ?><br>
                    </label>
<?php 
                $psacar_car->image_2->EditAttrs["onchange"] = "this.form.a_image_2[2].checked=true;" . @$psacar_car->image_2->EditAttrs["onchange"]; 
?>
<?php                 
                } 
                else { 
?>
                    <input type="hidden" name="a_image_2" id="a_image_2" value="3">
<?php                 
                } 
?>
                    <input type="file" name="x_image_2" id="x_image_2" title="<?php echo $psacar_car->image_2->FldTitle() ?>" size="30"<?php echo $psacar_car->image_2->EditAttributes() ?>>
                </div>
            </span>
<?php 
            echo $psacar_car->image_2->CustomMsg 
?>
        </td>
    </tr>
<?php } ?>
    
<?php 
if ($psacar_car->image_3->Visible) { // image     
?>
    <tr<?php echo $psacar_car->image_3->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_3->FldCaption() 
?>
        </td>
        <td<?php echo $psacar_car->image_3->CellAttributes() ?>>
            <span id="el_image_3">
                <div id="old_x_image_3">
                    <input type="hidden" name="x_id_image_3" id="x_id_image_3" value="<?php echo ew_HtmlEncode($psacar_car->id_image_3->CurrentValue) ?>">
<?php 
if ($psacar_car->image_3->HrefValue <> "" || $psacar_car->image_3->TooltipValue <> "") { 
?>
<?php 
    if (!empty($psacar_car->image_3->Upload->DbValue)) { 
?>
                    <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_3->UploadPath) . $psacar_car->image_3->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_3->ViewAttributes() ?>>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php 
    } 
?>
<?php 
} 
else {     
?>
<?php 
    if (!empty($psacar_car->image_3->Upload->DbValue)) {         
?>
        <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_3->UploadPath) . $psacar_car->image_3->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_3->ViewAttributes() ?>>
<?php 
?>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php     
    } 
?>
<?php 
} 
?>
                </div>
                <div id="new_ximage_3">
<?php 
                if (!empty($psacar_car->image_3->Upload->DbValue)) { 
?>
                    <label>
                        <input type="radio" name="a_image_3" id="a_image_3" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_3" id="a_image_3" value="2"><?php echo $Language->Phrase("Remove") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_3" id="a_image_3" value="3"><?php echo $Language->Phrase("Replace") ?><br>
                    </label>
<?php 
                $psacar_car->image_3->EditAttrs["onchange"] = "this.form.a_image_3[2].checked=true;" . @$psacar_car->image_3->EditAttrs["onchange"]; 
?>
<?php                 
                } 
                else { 
?>
                    <input type="hidden" name="a_image_3" id="a_image_3" value="3">
<?php                 
                } 
?>
                    <input type="file" name="x_image_3" id="x_image_3" title="<?php echo $psacar_car->image_3->FldTitle() ?>" size="30"<?php echo $psacar_car->image_3->EditAttributes() ?>>
                </div>
            </span>
<?php 
            echo $psacar_car->image_3->CustomMsg 
?>
        </td>
    </tr>
<?php } ?>  
    
<?php 
if ($psacar_car->image_4->Visible) { // image     
?>
    <tr<?php echo $psacar_car->image_4->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_4->FldCaption() 
?>
        </td>
        <td<?php echo $psacar_car->image_4->CellAttributes() ?>>
            <span id="el_image_4">
                <div id="old_x_image_4">
                    <input type="hidden" name="x_id_image_4" id="x_id_image_4" value="<?php echo ew_HtmlEncode($psacar_car->id_image_4->CurrentValue) ?>">                    
<?php 
if ($psacar_car->image_4->HrefValue <> "" || $psacar_car->image_4->TooltipValue <> "") { 
?>
<?php 
    if (!empty($psacar_car->image_4->Upload->DbValue)) { 
?>
                    <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_4->UploadPath) . $psacar_car->image_4->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_4->ViewAttributes() ?>>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php 
    } 
?>
<?php 
} 
else {     
?>
<?php 
    if (!empty($psacar_car->image_4->Upload->DbValue)) {         
?>
        <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_4->UploadPath) . $psacar_car->image_4->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_4->ViewAttributes() ?>>
<?php 
?>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php     
    } 
?>
<?php 
} 
?>
                </div>
                <div id="new_x_image_4">
<?php 
                if (!empty($psacar_car->image_4->Upload->DbValue)) { 
?>
                    <label>
                        <input type="radio" name="a_image_4" id="a_image_4" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_4" id="a_image_4" value="2"><?php echo $Language->Phrase("Remove") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_4" id="a_image_4" value="3"><?php echo $Language->Phrase("Replace") ?><br>
                    </label>
<?php 
                $psacar_car->image_4->EditAttrs["onchange"] = "this.form.a_image_4[2].checked=true;" . @$psacar_car->image_4->EditAttrs["onchange"]; 
?>
<?php                 
                } 
                else { 
?>
                    <input type="hidden" name="a_image_4" id="a_image_4" value="3">
<?php                 
                } 
?>
                    <input type="file" name="x_image_4" id="x_image_4" title="<?php echo $psacar_car->image_4->FldTitle() ?>" size="30"<?php echo $psacar_car->image_4->EditAttributes() ?>>
                </div>
            </span>
<?php 
            echo $psacar_car->image_4->CustomMsg 
?>
        </td>
    </tr>
<?php } ?>
    
<?php 
if ($psacar_car->image_5->Visible) { // image     
?>
    <tr<?php echo $psacar_car->image_5->RowAttributes ?>>
        <td class="ewTableHeader">
<?php 
            echo $psacar_car->image_5->FldCaption() 
?>
        </td>
        <td<?php echo $psacar_car->image_5->CellAttributes() ?>>
            <span id="el_image_5">
                <div id="old_x_image_5">
                    <input type="hidden" name="x_id_image_5" id="x_id_image_5" value="<?php echo ew_HtmlEncode($psacar_car->id_image_5->CurrentValue) ?>">
<?php 
if ($psacar_car->image_5->HrefValue <> "" || $psacar_car->image_5->TooltipValue <> "") { 
?>
<?php 
    if (!empty($psacar_car->image_5->Upload->DbValue)) { 
?>
                    <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_5->UploadPath) . $psacar_car->image_5->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_5->ViewAttributes() ?>>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php 
    } 
?>
<?php 
} 
else {     
?>
<?php 
    if (!empty($psacar_car->image_5->Upload->DbValue)) {         
?>
        <img width="50%" src="<?php echo ew_UploadPathEx(FALSE, $psacar_car->image_5->UploadPath) . $psacar_car->image_5->Upload->DbValue ?>" border=0<?php echo $psacar_car->image_5->ViewAttributes() ?>>
<?php 
?>
<?php     
    } 
    elseif (!in_array($psacar_car->CurrentAction, array("I", "edit", "gridedit"))) { 
?>	
&nbsp;
<?php     
    } 
?>
<?php 
} 
?>
                </div>
                <div id="new_x_image_5">
<?php 
                if (!empty($psacar_car->image_5->Upload->DbValue)) { 
?>
                    <label>
                        <input type="radio" name="a_image_5" id="a_image_5" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_5" id="a_image_5" value="2"><?php echo $Language->Phrase("Remove") ?>
                    </label>&nbsp;
                    <label>
                        <input type="radio" name="a_image_5" id="a_image_5" value="3"><?php echo $Language->Phrase("Replace") ?><br>
                    </label>
<?php 
                $psacar_car->image_5->EditAttrs["onchange"] = "this.form.a_image_5[2].checked=true;" . @$psacar_car->image_5->EditAttrs["onchange"]; 
?>
<?php                 
                } 
                else { 
?>
                    <input type="hidden" name="a_image_5" id="a_image_5" value="3">
<?php                 
                } 
?>
                    <input type="file" name="x_image_5" id="x_image_5" title="<?php echo $psacar_car->image_5->FldTitle() ?>" size="30"<?php echo $psacar_car->image_5->EditAttributes() ?>>
                </div>
            </span>
<?php 
            echo $psacar_car->image_5->CustomMsg 
?>
        </td>
    </tr>
<?php } ?>

                    </table>
                </div>
            </td></tr></table>
    <p>
        <input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<script type="text/javascript">
    <!--
    ew_CreateEditor();  // Create DHTML editor(s)

    //-->
</script>
<script language="JavaScript" type="text/javascript">
    <!--

    // Write your table-specific startup script here
    // document.write("page loaded");
    //-->

</script>
<?php include "footer.php" ?>
<?php
$psacar_car_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class cpsacar_car_edit {

    // Page ID
    var $PageID = 'edit';
    // Table name
    var $TableName = 'psacar_car';
    // Page object name
    var $PageObjName = 'psacar_car_edit';

    // Page name
    function PageName() {
        return ew_CurrentPage();
    }

    // Page URL
    function PageUrl() {
        $PageUrl = ew_CurrentPage() . "?";
        global $psacar_car;
        if ($psacar_car->UseTokenInUrl)
            $PageUrl .= "t=" . $psacar_car->TableVar . "&"; // Add page token
        return $PageUrl;
    }

    // Page URLs
    var $AddUrl;
    var $EditUrl;
    var $CopyUrl;
    var $DeleteUrl;
    var $ViewUrl;
    var $ListUrl;
    // Export URLs
    var $ExportPrintUrl;
    var $ExportHtmlUrl;
    var $ExportExcelUrl;
    var $ExportWordUrl;
    var $ExportXmlUrl;
    var $ExportCsvUrl;
    // Update URLs
    var $InlineAddUrl;
    var $InlineCopyUrl;
    var $InlineEditUrl;
    var $GridAddUrl;
    var $GridEditUrl;
    var $MultiDeleteUrl;
    var $MultiUpdateUrl;

    // Message
    function getMessage() {
        return @$_SESSION[EW_SESSION_MESSAGE];
    }

    function setMessage($v) {
        if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
            $_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
        } else {
            $_SESSION[EW_SESSION_MESSAGE] = $v;
        }
    }

    // Show message
    function ShowMessage() {
        $sMessage = $this->getMessage();
        $this->Message_Showing($sMessage);
        if ($sMessage <> "") { // Message in Session, display
            echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
            $_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
        }
    }

    // Validate page request
    function IsPageRequest() {
        global $objForm, $psacar_car;
        if ($psacar_car->UseTokenInUrl) {
            if ($objForm)
                return ($psacar_car->TableVar == $objForm->GetValue("t"));
            if (@$_GET["t"] <> "")
                return ($psacar_car->TableVar == $_GET["t"]);
        } else {
            return TRUE;
        }
    }

    //
    // Page class constructor
    //
	function cpsacar_car_edit() {
        global $conn, $Language;

        // Language object
        $Language = new cLanguage();

        // Table object (psacar_car)
        $GLOBALS["psacar_car"] = new cpsacar_car();

        // Table object (psacar_user)
        $GLOBALS['psacar_user'] = new cpsacar_user();

        // Page ID
        if (!defined("EW_PAGE_ID"))
            define("EW_PAGE_ID", 'edit', TRUE);

        // Table name (for backward compatibility)
        if (!defined("EW_TABLE_NAME"))
            define("EW_TABLE_NAME", 'psacar_car', TRUE);

        // Start timer
        $GLOBALS["gsTimer"] = new cTimer();

        // Open connection
        $conn = ew_Connect();
    }

    // 
    //  Page_Init
    //
	function Page_Init() {
        global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
        global $psacar_car;

        // Security
        $Security = new cAdvancedSecurity();
        if (!$Security->IsLoggedIn())
            $Security->AutoLogin();
        if (!$Security->IsLoggedIn()) {
            $Security->SaveLastUrl();
            $this->Page_Terminate("login.php");
        }

        // Create form object
        $objForm = new cFormObj();

        // Global Page Loading event (in userfn*.php)
        Page_Loading();

        // Page Load event
        $this->Page_Load();
    }

    //
    // Page_Terminate
    //
	function Page_Terminate($url = "") {
        global $conn;

        // Page Unload event
        $this->Page_Unload();

        // Global Page Unloaded event (in userfn*.php)
        Page_Unloaded();

        // Close connection
        $conn->Close();

        // Go to URL if specified
        $this->Page_Redirecting($url);
        if ($url <> "") {
            if (!EW_DEBUG_ENABLED && ob_get_length())
                ob_end_clean();
            header("Location: " . $url);
        }
        exit();
    }

    var $sDbMasterFilter;
    var $sDbDetailFilter;

    // 
    // Page main
    //
	function Page_Main() {
        global $objForm, $Language, $gsFormError, $psacar_car;

        // Load key from QueryString
        if (@$_GET["id"] <> "")
            $psacar_car->id->setQueryStringValue($_GET["id"]);
        if (@$_POST["a_edit"] <> "") {
            $psacar_car->CurrentAction = $_POST["a_edit"]; // Get action code
            $this->GetUploadFiles(); // Get upload files
            $this->LoadFormValues(); // Get form values
            // Validate form
            if (!$this->ValidateForm()) {
                $psacar_car->CurrentAction = ""; // Form error, reset action
                $this->setMessage($gsFormError);
                $psacar_car->EventCancelled = TRUE; // Event cancelled
                $this->RestoreFormValues();
            }
        } else {
            $psacar_car->CurrentAction = "I"; // Default action is display
        }

        // Check if valid key
        if ($psacar_car->id->CurrentValue == "")
            $this->Page_Terminate("psacar_carlist.php"); // Invalid key, return to list
        switch ($psacar_car->CurrentAction) {
            case "I": // Get a record to display
                if (!$this->LoadRow()) { // Load record based on key
                    $this->setMessage($Language->Phrase("NoRecord")); // No record found
                    $this->Page_Terminate("psacar_carlist.php"); // No matching record, return to list
                }
                break;
            Case "U": // Update
                $psacar_car->SendEmail = TRUE; // Send email on update success
                if ($this->EditRow()) { // Update record based on key
                    $this->setMessage($Language->Phrase("UpdateSuccess")); // Update success
                    $sReturnUrl = $psacar_car->getReturnUrl();
                    $this->Page_Terminate($sReturnUrl); // Return to caller
                } else {
                    $psacar_car->EventCancelled = TRUE; // Event cancelled
                    $this->RestoreFormValues(); // Restore form values if update failed
                }
        }

        // Render the record
        $psacar_car->RowType = EW_ROWTYPE_EDIT; // Render as Edit
        $this->RenderRow();
    }

    // Get upload files
    function GetUploadFiles() {
        global $objForm, $psacar_car;

        // Get upload data
        if ($psacar_car->image_1->Upload->UploadFile()) {
            // No action required                
        } else {                
            echo $psacar_car->image_1->Upload->Message;
            $this->Page_Terminate();
            exit();
        }     

        if ($psacar_car->image_2->Upload->UploadFile()) {
            // No action required                
        } else {                
            echo $psacar_car->image_2->Upload->Message;
            $this->Page_Terminate();
            exit();
        }                                    

        if ($psacar_car->image_3->Upload->UploadFile()) {
            // No action required                
        } else {                
            echo $psacar_car->image_3->Upload->Message;
            $this->Page_Terminate();
            exit();
        }                                    

        if ($psacar_car->image_4->Upload->UploadFile()) {
            // No action required                
        } else {                
            echo $psacar_car->image_4->Upload->Message;
            $this->Page_Terminate();
            exit();
        }                                    

        if ($psacar_car->image_5->Upload->UploadFile()) {
            // No action required                
        } else {                
            echo $psacar_car->image_5->Upload->Message;
            $this->Page_Terminate();
            exit();
        }                                    
    }

    // Load form values
    function LoadFormValues() {
        // Load from form
        global $objForm, $psacar_car;
        $psacar_car->id->setFormValue($objForm->GetValue("x_id"));
        $psacar_car->dealer_id->setFormValue($objForm->GetValue("x_dealer_id"));
        $psacar_car->model_id->setFormValue($objForm->GetValue("x_model_id"));
        $psacar_car->year->setFormValue($objForm->GetValue("x_year"));
        $psacar_car->type_id->setFormValue($objForm->GetValue("x_type_id"));
        $psacar_car->category_id->setFormValue($objForm->GetValue("x_category_id"));
        $psacar_car->description->setFormValue($objForm->GetValue("x_description"));
        $psacar_car->price->setFormValue($objForm->GetValue("x_price"));
        $psacar_car->quality->setFormValue($objForm->GetValue("x_quality"));
        $psacar_car->post_date->setFormValue($objForm->GetValue("x_post_date"));
        $psacar_car->post_date->CurrentValue = ew_UnFormatDateTime($psacar_car->post_date->CurrentValue, 5);
        $psacar_car->expiration_date->setFormValue($objForm->GetValue("x_expiration_date"));
        $psacar_car->expiration_date->CurrentValue = ew_UnFormatDateTime($psacar_car->expiration_date->CurrentValue, 5);
        $psacar_car->internal_color_id->setFormValue($objForm->GetValue("x_internal_color_id"));
        $psacar_car->external_color_id->setFormValue($objForm->GetValue("x_external_color_id"));
        $psacar_car->transmission->setFormValue($objForm->GetValue("x_transmission"));
        $psacar_car->legal->setFormValue($objForm->GetValue("x_legal"));
        $psacar_car->import_tax->setFormValue($objForm->GetValue("x_import_tax"));
        $psacar_car->drive_train->setFormValue($objForm->GetValue("x_drive_train"));
        $psacar_car->door_count->setFormValue($objForm->GetValue("x_door_count"));
        $psacar_car->fuel->setFormValue($objForm->GetValue("x_fuel"));
        $psacar_car->vat->setFormValue($objForm->GetValue("x_vat"));
        $psacar_car->destinations->setFormValue($objForm->GetValue("x_destinations"));
        $psacar_car->rent_type->setFormValue($objForm->GetValue("x_rent_type"));
        $psacar_car->vehicle_type_id->setFormValue($objForm->GetValue("x_vehicle_type_id"));
        $psacar_car->is_driver->setFormValue($objForm->GetValue("x_is_driver"));
        $psacar_car->vehicle_id_number->setFormValue($objForm->GetValue("x_vehicle_id_number"));
        $psacar_car->negotiate->setFormValue($objForm->GetValue("x_negotiate"));
        $psacar_car->duration->setFormValue($objForm->GetValue("x_duration"));
        $psacar_car->create_date->setFormValue($objForm->GetValue("x_create_date"));
        $psacar_car->create_date->CurrentValue = ew_UnFormatDateTime($psacar_car->create_date->CurrentValue, 5);
        $psacar_car->end_date->setFormValue($objForm->GetValue("x_end_date"));
        $psacar_car->end_date->CurrentValue = ew_UnFormatDateTime($psacar_car->end_date->CurrentValue, 5);
        $psacar_car->status->setFormValue($objForm->GetValue("x_status"));
        $psacar_car->code->setFormValue($objForm->GetValue("x_code"));
        $psacar_car->created_date->setFormValue($objForm->GetValue("x_created_date"));
        $psacar_car->created_date->CurrentValue = ew_UnFormatDateTime($psacar_car->created_date->CurrentValue, 5);
        $psacar_car->modified_date->setFormValue($objForm->GetValue("x_modified_date"));
        $psacar_car->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_car->modified_date->CurrentValue, 5);
        
        $psacar_car->id_image_1->setFormValue($objForm->GetValue("x_id_image_1"));
        $psacar_car->id_image_2->setFormValue($objForm->GetValue("x_id_image_2"));
        $psacar_car->id_image_3->setFormValue($objForm->GetValue("x_id_image_3"));
        $psacar_car->id_image_4->setFormValue($objForm->GetValue("x_id_image_4"));
        $psacar_car->id_image_5->setFormValue($objForm->GetValue("x_id_image_5"));
    }

    // Restore form values
    function RestoreFormValues() {
        global $objForm, $psacar_car;
        $this->LoadRow();
        $psacar_car->id->CurrentValue = $psacar_car->id->FormValue;
        $psacar_car->dealer_id->CurrentValue = $psacar_car->dealer_id->FormValue;
        $psacar_car->model_id->CurrentValue = $psacar_car->model_id->FormValue;
        $psacar_car->year->CurrentValue = $psacar_car->year->FormValue;
        $psacar_car->type_id->CurrentValue = $psacar_car->type_id->FormValue;
        $psacar_car->category_id->CurrentValue = $psacar_car->category_id->FormValue;
        $psacar_car->description->CurrentValue = $psacar_car->description->FormValue;
        $psacar_car->price->CurrentValue = $psacar_car->price->FormValue;
        $psacar_car->quality->CurrentValue = $psacar_car->quality->FormValue;
        $psacar_car->post_date->CurrentValue = $psacar_car->post_date->FormValue;
        $psacar_car->post_date->CurrentValue = ew_UnFormatDateTime($psacar_car->post_date->CurrentValue, 5);
        $psacar_car->expiration_date->CurrentValue = $psacar_car->expiration_date->FormValue;
        $psacar_car->expiration_date->CurrentValue = ew_UnFormatDateTime($psacar_car->expiration_date->CurrentValue, 5);
        $psacar_car->internal_color_id->CurrentValue = $psacar_car->internal_color_id->FormValue;
        $psacar_car->external_color_id->CurrentValue = $psacar_car->external_color_id->FormValue;
        $psacar_car->transmission->CurrentValue = $psacar_car->transmission->FormValue;
        $psacar_car->legal->CurrentValue = $psacar_car->legal->FormValue;
        $psacar_car->import_tax->CurrentValue = $psacar_car->import_tax->FormValue;
        $psacar_car->drive_train->CurrentValue = $psacar_car->drive_train->FormValue;
        $psacar_car->door_count->CurrentValue = $psacar_car->door_count->FormValue;
        $psacar_car->fuel->CurrentValue = $psacar_car->fuel->FormValue;
        $psacar_car->vat->CurrentValue = $psacar_car->vat->FormValue;
        $psacar_car->destinations->CurrentValue = $psacar_car->destinations->FormValue;
        $psacar_car->rent_type->CurrentValue = $psacar_car->rent_type->FormValue;
        $psacar_car->vehicle_type_id->CurrentValue = $psacar_car->vehicle_type_id->FormValue;
        $psacar_car->is_driver->CurrentValue = $psacar_car->is_driver->FormValue;
        $psacar_car->vehicle_id_number->CurrentValue = $psacar_car->vehicle_id_number->FormValue;
        $psacar_car->negotiate->CurrentValue = $psacar_car->negotiate->FormValue;
        $psacar_car->duration->CurrentValue = $psacar_car->duration->FormValue;
        $psacar_car->create_date->CurrentValue = $psacar_car->create_date->FormValue;
        $psacar_car->create_date->CurrentValue = ew_UnFormatDateTime($psacar_car->create_date->CurrentValue, 5);
        $psacar_car->end_date->CurrentValue = $psacar_car->end_date->FormValue;
        $psacar_car->end_date->CurrentValue = ew_UnFormatDateTime($psacar_car->end_date->CurrentValue, 5);
        $psacar_car->status->CurrentValue = $psacar_car->status->FormValue;
        $psacar_car->code->CurrentValue = $psacar_car->code->FormValue;
        $psacar_car->created_date->CurrentValue = $psacar_car->created_date->FormValue;
        $psacar_car->created_date->CurrentValue = ew_UnFormatDateTime($psacar_car->created_date->CurrentValue, 5);
        $psacar_car->modified_date->CurrentValue = $psacar_car->modified_date->FormValue;
        $psacar_car->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_car->modified_date->CurrentValue, 5);
        
        $psacar_car->id_image_1->CurrentValue = $psacar_car->id_image_1->FormValue;
        $psacar_car->id_image_2->CurrentValue = $psacar_car->id_image_2->FormValue;
        $psacar_car->id_image_3->CurrentValue = $psacar_car->id_image_3->FormValue;
        $psacar_car->id_image_4->CurrentValue = $psacar_car->id_image_4->FormValue;
        $psacar_car->id_image_5->CurrentValue = $psacar_car->id_image_5->FormValue;
    }

    // Load row based on key values
    function LoadRow() {
        global $conn, $Security, $psacar_car;
        $sFilter = $psacar_car->KeyFilter();

        // Call Row Selecting event
        $psacar_car->Row_Selecting($sFilter);

        // Load SQL based on filter
        $psacar_car->CurrentFilter = $sFilter;
        $sSql = $psacar_car->SQL();
        
        $res = FALSE;
        $rs = ew_LoadRecordset($sSql);
        if ($rs && !$rs->EOF) {
            $res = TRUE;
            $this->LoadRowValues($rs); // Load row values
            // Call Row Selected event
            $psacar_car->Row_Selected($rs);
            $rs->Close();
        }
        return $res;
    }

    // Load row values from recordset
    function LoadRowValues(&$rs) {
        global $conn, $psacar_car;
        $psacar_car->id->setDbValue($rs->fields('id'));
        $psacar_car->dealer_id->setDbValue($rs->fields('dealer_id'));
        $psacar_car->model_id->setDbValue($rs->fields('model_id'));
        $psacar_car->year->setDbValue($rs->fields('year'));
        $psacar_car->external_color_id->setDbValue($rs->fields('external_color_id'));
        $psacar_car->type_id->setDbValue($rs->fields('type_id'));
        $psacar_car->category_id->setDbValue($rs->fields('category_id'));
        $psacar_car->description->setDbValue($rs->fields('description'));
        $psacar_car->price->setDbValue($rs->fields('price'));
        $psacar_car->quality->setDbValue($rs->fields('quality'));
        $psacar_car->post_by->setDbValue($rs->fields('post_by'));
        $psacar_car->post_date->setDbValue($rs->fields('post_date'));
        $psacar_car->expiration_date->setDbValue($rs->fields('expiration_date'));
        $psacar_car->number_votes->setDbValue($rs->fields('number_votes'));
        $psacar_car->total_points->setDbValue($rs->fields('total_points'));
        $psacar_car->dec_avg->setDbValue($rs->fields('dec_avg'));
        $psacar_car->whole_avg->setDbValue($rs->fields('whole_avg'));
        $psacar_car->internal_color_id->setDbValue($rs->fields('internal_color_id'));
        $psacar_car->external_color_id->setDbValue($rs->fields('external_color_id'));
        $psacar_car->transmission->setDbValue($rs->fields('transmission'));
        $psacar_car->legal->setDbValue($rs->fields('legal'));
        $psacar_car->import_tax->setDbValue($rs->fields('import_tax'));
        $psacar_car->drive_train->setDbValue($rs->fields('drive_train'));
        $psacar_car->door_count->setDbValue($rs->fields('door_count'));
        $psacar_car->fuel->setDbValue($rs->fields('fuel'));
        $psacar_car->vat->setDbValue($rs->fields('vat'));
        $psacar_car->destinations->setDbValue($rs->fields('destinations'));
        $psacar_car->rent_type->setDbValue($rs->fields('rent_type'));
        $psacar_car->vehicle_type_id->setDbValue($rs->fields('vehicle_type_id'));
        $psacar_car->is_driver->setDbValue($rs->fields('is_driver'));        
        $psacar_car->vehicle_id_number->setDbValue($rs->fields('vehicle_id_number'));
        $psacar_car->negotiate->setDbValue($rs->fields('negotiate'));
        $psacar_car->duration_type->setDbValue($rs->fields('duration_type'));
        $psacar_car->duration->setDbValue($rs->fields('duration'));
        $psacar_car->create_date->setDbValue($rs->fields('create_date'));
        $psacar_car->end_date->setDbValue($rs->fields('end_date'));
        $psacar_car->status->setDbValue($rs->fields('status'));
        $psacar_car->code->setDbValue($rs->fields('code'));
        $psacar_car->created_date->setDbValue($rs->fields('created_date'));
        $psacar_car->modified_date->setDbValue($rs->fields('modified_date'));
        
        //Image
        $psacar_car_image = new cpsacar_car_image();        
        // Load List page SQL
        $psacar_car_image->CurrentFilter = "`car_id` = " . $rs->fields('id');
        $sSql = $psacar_car_image->SelectSQL();
        // Load recordset
        $rs_image = ew_LoadRecordset($sSql);
        if ($rs_image && !$rs_image->EOF) {
            $rs_image->MoveFirst();
        }
        
        $counter = 1;
        while (!$rs_image->EOF) {
            //echo $rs_image->fields('image') . '<br>';
            switch($counter) {
                case 1:
                    $psacar_car->image_1->Upload->DbValue = $rs_image->fields('image');
                    $psacar_car->id_image_1->setDbValue($rs_image->fields('id'));
                    break;
                case 2:
                    $psacar_car->image_2->Upload->DbValue = $rs_image->fields('image');
                    $psacar_car->id_image_2->setDbValue($rs_image->fields('id'));
                    break;
                case 3:
                    $psacar_car->image_3->Upload->DbValue = $rs_image->fields('image');
                    $psacar_car->id_image_3->setDbValue($rs_image->fields('id'));
                    break;
                case 4:
                    $psacar_car->image_4->Upload->DbValue = $rs_image->fields('image');
                    $psacar_car->id_image_4->setDbValue($rs_image->fields('id'));
                    break;
                case 5:
                    $psacar_car->image_5->Upload->DbValue = $rs_image->fields('image');
                    $psacar_car->id_image_5->setDbValue($rs_image->fields('id'));
                    break;
            }
            
            $counter += 1;
            $rs_image->MoveNext();
        }
        
        if ($rs_image)
            $rs_image->Close();        
    }

    // Render row values based on field settings
    function RenderRow() {
        global $conn, $Security, $Language, $psacar_car;

        // Initialize URLs
        // Call Row_Rendering event

        $psacar_car->Row_Rendering();

        // Common render codes for all row types
        // id

        $psacar_car->id->CellCssStyle = "";
        $psacar_car->id->CellCssClass = "";
        $psacar_car->id->CellAttrs = array();
        $psacar_car->id->ViewAttrs = array();
        $psacar_car->id->EditAttrs = array();

        // dealer_id
        $psacar_car->dealer_id->CellCssStyle = "";
        $psacar_car->dealer_id->CellCssClass = "";
        $psacar_car->dealer_id->CellAttrs = array();
        $psacar_car->dealer_id->ViewAttrs = array();
        $psacar_car->dealer_id->EditAttrs = array();

        // model_id
        $psacar_car->model_id->CellCssStyle = "";
        $psacar_car->model_id->CellCssClass = "";
        $psacar_car->model_id->CellAttrs = array();
        $psacar_car->model_id->ViewAttrs = array();
        $psacar_car->model_id->EditAttrs = array();

        // year
        $psacar_car->year->CellCssStyle = "";
        $psacar_car->year->CellCssClass = "";
        $psacar_car->year->CellAttrs = array();
        $psacar_car->year->ViewAttrs = array();
        $psacar_car->year->EditAttrs = array();

        // type_id
        $psacar_car->type_id->CellCssStyle = "";
        $psacar_car->type_id->CellCssClass = "";
        $psacar_car->type_id->CellAttrs = array();
        $psacar_car->type_id->ViewAttrs = array();
        $psacar_car->type_id->EditAttrs = array();

        // category_id
        $psacar_car->category_id->CellCssStyle = "";
        $psacar_car->category_id->CellCssClass = "";
        $psacar_car->category_id->CellAttrs = array();
        $psacar_car->category_id->ViewAttrs = array();
        $psacar_car->category_id->EditAttrs = array();

        // description
        $psacar_car->description->CellCssStyle = "";
        $psacar_car->description->CellCssClass = "";
        $psacar_car->description->CellAttrs = array();
        $psacar_car->description->ViewAttrs = array();
        $psacar_car->description->EditAttrs = array();

        // price
        $psacar_car->price->CellCssStyle = "";
        $psacar_car->price->CellCssClass = "";
        $psacar_car->price->CellAttrs = array();
        $psacar_car->price->ViewAttrs = array();
        $psacar_car->price->EditAttrs = array();

        // quality
        $psacar_car->quality->CellCssStyle = "";
        $psacar_car->quality->CellCssClass = "";
        $psacar_car->quality->CellAttrs = array();
        $psacar_car->quality->ViewAttrs = array();
        $psacar_car->quality->EditAttrs = array();

        // post_date
        $psacar_car->post_date->CellCssStyle = "";
        $psacar_car->post_date->CellCssClass = "";
        $psacar_car->post_date->CellAttrs = array();
        $psacar_car->post_date->ViewAttrs = array();
        $psacar_car->post_date->EditAttrs = array();

        // expiration_date
        $psacar_car->expiration_date->CellCssStyle = "";
        $psacar_car->expiration_date->CellCssClass = "";
        $psacar_car->expiration_date->CellAttrs = array();
        $psacar_car->expiration_date->ViewAttrs = array();
        $psacar_car->expiration_date->EditAttrs = array();

        // internal_color_id
        $psacar_car->internal_color_id->CellCssStyle = "";
        $psacar_car->internal_color_id->CellCssClass = "";
        $psacar_car->internal_color_id->CellAttrs = array();
        $psacar_car->internal_color_id->ViewAttrs = array();
        $psacar_car->internal_color_id->EditAttrs = array();

        // internal_color_id
        $psacar_car->external_color_id->CellCssStyle = "";
        $psacar_car->external_color_id->CellCssClass = "";
        $psacar_car->external_color_id->CellAttrs = array();
        $psacar_car->external_color_id->ViewAttrs = array();
        $psacar_car->external_color_id->EditAttrs = array();

        // transmission
        $psacar_car->transmission->CellCssStyle = "";
        $psacar_car->transmission->CellCssClass = "";
        $psacar_car->transmission->CellAttrs = array();
        $psacar_car->transmission->ViewAttrs = array();
        $psacar_car->transmission->EditAttrs = array();

        // legal
        $psacar_car->legal->CellCssStyle = "";
        $psacar_car->legal->CellCssClass = "";
        $psacar_car->legal->CellAttrs = array();
        $psacar_car->legal->ViewAttrs = array();
        $psacar_car->legal->EditAttrs = array();

        // import_tax
        $psacar_car->import_tax->CellCssStyle = "";
        $psacar_car->import_tax->CellCssClass = "";
        $psacar_car->import_tax->CellAttrs = array();
        $psacar_car->import_tax->ViewAttrs = array();
        $psacar_car->import_tax->EditAttrs = array();

        // drive_train
        $psacar_car->drive_train->CellCssStyle = "";
        $psacar_car->drive_train->CellCssClass = "";
        $psacar_car->drive_train->CellAttrs = array();
        $psacar_car->drive_train->ViewAttrs = array();
        $psacar_car->drive_train->EditAttrs = array();

        // door_count
        $psacar_car->door_count->CellCssStyle = "";
        $psacar_car->door_count->CellCssClass = "";
        $psacar_car->door_count->CellAttrs = array();
        $psacar_car->door_count->ViewAttrs = array();
        $psacar_car->door_count->EditAttrs = array();

        // fuel
        $psacar_car->fuel->CellCssStyle = "";
        $psacar_car->fuel->CellCssClass = "";
        $psacar_car->fuel->CellAttrs = array();
        $psacar_car->fuel->ViewAttrs = array();
        $psacar_car->fuel->EditAttrs = array();

        // vat
        $psacar_car->vat->CellCssStyle = "";
        $psacar_car->vat->CellCssClass = "";
        $psacar_car->vat->CellAttrs = array();
        $psacar_car->vat->ViewAttrs = array();
        $psacar_car->vat->EditAttrs = array();

        // destinations
        $psacar_car->destinations->CellCssStyle = "";
        $psacar_car->destinations->CellCssClass = "";
        $psacar_car->destinations->CellAttrs = array();
        $psacar_car->destinations->ViewAttrs = array();
        $psacar_car->destinations->EditAttrs = array();

        // rent_type
        $psacar_car->rent_type->CellCssStyle = "";
        $psacar_car->rent_type->CellCssClass = "";
        $psacar_car->rent_type->CellAttrs = array();
        $psacar_car->rent_type->ViewAttrs = array();
        $psacar_car->rent_type->EditAttrs = array();

        // vehicle_type_id
        $psacar_car->vehicle_type_id->CellCssStyle = "";
        $psacar_car->vehicle_type_id->CellCssClass = "";
        $psacar_car->vehicle_type_id->CellAttrs = array();
        $psacar_car->vehicle_type_id->ViewAttrs = array();
        $psacar_car->vehicle_type_id->EditAttrs = array();

        // is_driver
        $psacar_car->is_driver->CellCssStyle = "";
        $psacar_car->is_driver->CellCssClass = "";
        $psacar_car->is_driver->CellAttrs = array();
        $psacar_car->is_driver->ViewAttrs = array();
        $psacar_car->is_driver->EditAttrs = array();

        // image_1
        $psacar_car->image_1->CellCssStyle = "";
        $psacar_car->image_1->CellCssClass = "";
        $psacar_car->image_1->CellAttrs = array();
        $psacar_car->image_1->ViewAttrs = array();
        $psacar_car->image_1->EditAttrs = array();

        // image_2
        $psacar_car->image_2->CellCssStyle = "";
        $psacar_car->image_2->CellCssClass = "";
        $psacar_car->image_2->CellAttrs = array();
        $psacar_car->image_2->ViewAttrs = array();
        $psacar_car->image_2->EditAttrs = array();
        
        // image_3
        $psacar_car->image_3->CellCssStyle = "";
        $psacar_car->image_3->CellCssClass = "";
        $psacar_car->image_3->CellAttrs = array();
        $psacar_car->image_3->ViewAttrs = array();
        $psacar_car->image_3->EditAttrs = array();

        // image_4
        $psacar_car->image_4->CellCssStyle = "";
        $psacar_car->image_4->CellCssClass = "";
        $psacar_car->image_4->CellAttrs = array();
        $psacar_car->image_4->ViewAttrs = array();
        $psacar_car->image_4->EditAttrs = array();

        // image_5
        $psacar_car->image_5->CellCssStyle = "";
        $psacar_car->image_5->CellCssClass = "";
        $psacar_car->image_5->CellAttrs = array();
        $psacar_car->image_5->ViewAttrs = array();
        $psacar_car->image_5->EditAttrs = array();

        // vehicle_id_number
        $psacar_car->vehicle_id_number->CellCssStyle = "";
        $psacar_car->vehicle_id_number->CellCssClass = "";
        $psacar_car->vehicle_id_number->CellAttrs = array();
        $psacar_car->vehicle_id_number->ViewAttrs = array();
        $psacar_car->vehicle_id_number->EditAttrs = array();

        // negotiate
        $psacar_car->negotiate->CellCssStyle = "";
        $psacar_car->negotiate->CellCssClass = "";
        $psacar_car->negotiate->CellAttrs = array();
        $psacar_car->negotiate->ViewAttrs = array();
        $psacar_car->negotiate->EditAttrs = array();

        // duration
        $psacar_car->duration->CellCssStyle = "";
        $psacar_car->duration->CellCssClass = "";
        $psacar_car->duration->CellAttrs = array();
        $psacar_car->duration->ViewAttrs = array();
        $psacar_car->duration->EditAttrs = array();

        // create_date
        $psacar_car->create_date->CellCssStyle = "";
        $psacar_car->create_date->CellCssClass = "";
        $psacar_car->create_date->CellAttrs = array();
        $psacar_car->create_date->ViewAttrs = array();
        $psacar_car->create_date->EditAttrs = array();

        // end_date
        $psacar_car->end_date->CellCssStyle = "";
        $psacar_car->end_date->CellCssClass = "";
        $psacar_car->end_date->CellAttrs = array();
        $psacar_car->end_date->ViewAttrs = array();
        $psacar_car->end_date->EditAttrs = array();

        // status
        $psacar_car->status->CellCssStyle = "";
        $psacar_car->status->CellCssClass = "";
        $psacar_car->status->CellAttrs = array();
        $psacar_car->status->ViewAttrs = array();
        $psacar_car->status->EditAttrs = array();

        // code
        $psacar_car->code->CellCssStyle = "";
        $psacar_car->code->CellCssClass = "";
        $psacar_car->code->CellAttrs = array();
        $psacar_car->code->ViewAttrs = array();
        $psacar_car->code->EditAttrs = array();

        // created_date
        $psacar_car->created_date->CellCssStyle = "";
        $psacar_car->created_date->CellCssClass = "";
        $psacar_car->created_date->CellAttrs = array();
        $psacar_car->created_date->ViewAttrs = array();
        $psacar_car->created_date->EditAttrs = array();

        // modified_date
        $psacar_car->modified_date->CellCssStyle = "";
        $psacar_car->modified_date->CellCssClass = "";
        $psacar_car->modified_date->CellAttrs = array();
        $psacar_car->modified_date->ViewAttrs = array();
        $psacar_car->modified_date->EditAttrs = array();
        if ($psacar_car->RowType == EW_ROWTYPE_VIEW) { // View row
        } elseif ($psacar_car->RowType == EW_ROWTYPE_EDIT) { // Edit row
            // id
            $psacar_car->id->EditCustomAttributes = "";
            $psacar_car->id->EditValue = $psacar_car->id->CurrentValue;
            $psacar_car->id->CssStyle = "";
            $psacar_car->id->CssClass = "";
            $psacar_car->id->ViewCustomAttributes = "";

            // dealer_id
            $psacar_car->dealer_id->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_member`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->dealer_id->EditValue = $arwrk;

            // model_id
            $psacar_car->model_id->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM psacar_model";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->model_id->EditValue = $arwrk;

            // year
            $psacar_car->year->EditCustomAttributes = "";
            $psacar_car->year->EditValue = $psacar_car->year->CurrentValue;
            $psacar_car->year->CssStyle = "";
            $psacar_car->year->CssClass = "";
            $psacar_car->year->ViewCustomAttributes = "";

            // type_id
            $psacar_car->type_id->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_car_type`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->type_id->EditValue = $arwrk;

            // category_id
            $psacar_car->category_id->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `category_id`, `category_name`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_category`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->category_id->EditValue = $arwrk;

            // description
            $psacar_car->description->EditCustomAttributes = "";
            $psacar_car->description->EditValue = ew_HtmlEncode($psacar_car->description->CurrentValue);

            // price
            $psacar_car->price->EditCustomAttributes = "";
            $psacar_car->price->EditValue = ew_HtmlEncode($psacar_car->price->CurrentValue);

            // quality
            $psacar_car->quality->EditCustomAttributes = "";
            $psacar_car->quality->EditValue = ew_HtmlEncode($psacar_car->quality->CurrentValue);
            if (strval($psacar_car->quality->CurrentValue) <> "") {
                $sFilterWrk = "`code` = " . ew_AdjustSql($psacar_car->quality->CurrentValue) . "";
                $sSqlWrk = "SELECT `mileage` FROM `psacar_mileage`";
                $sWhereWrk = "";
                if ($sFilterWrk <> "") {
                    if ($sWhereWrk <> "")
                        $sWhereWrk .= " AND ";
                    $sWhereWrk .= "(" . $sFilterWrk . ")";
                }
                if ($sWhereWrk <> "")
                    $sSqlWrk .= " WHERE " . $sWhereWrk;
                $rswrk = $conn->Execute($sSqlWrk);
                if ($rswrk && !$rswrk->EOF) { // Lookup values found
                    $psacar_car->quality->EditValue = $rswrk->fields('mileage');
                    $rswrk->Close();
                } else {
                    $psacar_car->quality->EditValue = $psacar_car->quality->CurrentValue;
                }
            } else {
                $psacar_car->quality->EditValue = NULL;
            }

            // post_date
            $psacar_car->post_date->EditCustomAttributes = "";
            $psacar_car->post_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->post_date->CurrentValue, 5));

            // expiration_date
            $psacar_car->expiration_date->EditCustomAttributes = "";
            $psacar_car->expiration_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->expiration_date->CurrentValue, 5));

            // external_color_id
            $psacar_car->external_color_id->EditCustomAttributes = "";
            $sFilterWrk = "category_id = 2";
            $sSqlWrk = "SELECT `id`, `color`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_color`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk . ' ORDER BY `color`');
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->external_color_id->EditValue = $arwrk;

            // internal_color_id
            $psacar_car->internal_color_id->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `color`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_color`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->internal_color_id->EditValue = $arwrk;

            // transmission
            $psacar_car->transmission->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `transmission`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_transmission`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->transmission->EditValue = $arwrk;

            // legal
            $psacar_car->legal->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Owner transfer fee included");
            $arwrk[] = array("1", "Owner transfer fee not included");
            $arwrk[] = array("2", "Others");
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->legal->EditValue = $arwrk;

            // import_tax
            $psacar_car->import_tax->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Yes");
            $arwrk[] = array("1", "No");
            $arwrk[] = array("2", "Other");
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->import_tax->EditValue = $arwrk;

            // drive_train
            $psacar_car->drive_train->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `drivetrain`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_drivetrain`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->drive_train->EditValue = $arwrk;

            // door_count
            $psacar_car->door_count->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", $Language->Phrase("PleaseSelect"));
            for ($counter = 1; $counter <= 10; $counter++)
                $arwrk[] = array($counter, $counter);
            $psacar_car->door_count->EditValue = $arwrk;

            // fuel
            $psacar_car->fuel->EditCustomAttributes = "";
            $sFilterWrk = "";
            $sSqlWrk = "SELECT `id`, `fuel`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_fuel`";
            $sWhereWrk = "";
            if ($sFilterWrk <> "") {
                if ($sWhereWrk <> "")
                    $sWhereWrk .= " AND ";
                $sWhereWrk .= "(" . $sFilterWrk . ")";
            }
            if ($sWhereWrk <> "")
                $sSqlWrk .= " WHERE " . $sWhereWrk;
            $rswrk = $conn->Execute($sSqlWrk);
            $arwrk = ($rswrk) ? $rswrk->GetRows() : array();
            if ($rswrk)
                $rswrk->Close();
            $psacar_car->fuel->EditValue = $arwrk;

            // vat
            $psacar_car->vat->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Included");
            $arwrk[] = array("1", "Not included");
            $psacar_car->vat->EditValue = $arwrk;

            // destinations
            $psacar_car->destinations->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Airport Pickup");
            $arwrk[] = array("1", "Airport Drop off");
            $arwrk[] = array("2", "Hourly");
            $arwrk[] = array("3", "Hafday");
            $arwrk[] = array("4", "Full day");
            $arwrk[] = array("5", "Tour Package");
            $arwrk[] = array("", "");
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->destinations->EditValue = $arwrk;

            // rent_type
            $psacar_car->rent_type->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Long term leasing");
            $arwrk[] = array("1", "Short term leasing");
            $arwrk[] = array("2", "Tour Package");
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->rent_type->EditValue = $arwrk;

            // vehicle_type_id
            $psacar_car->vehicle_type_id->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Buy");
            $arwrk[] = array("1", "Sale");
            $arwrk[] = array("2", "Rent");
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->vehicle_type_id->EditValue = $arwrk;

            // is_driver
            $psacar_car->is_driver->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "With Driver");
            $arwrk[] = array("1", "Without Driver");
            $psacar_car->is_driver->EditValue = $arwrk;

            // image_1
            $psacar_car->image_1->EditCustomAttributes = "";
            if (!ew_Empty($psacar_car->image_1->Upload->DbValue)) {
                $psacar_car->image_1->EditValue = $psacar_car->image_1->Upload->DbValue;
            } else {
                $psacar_car->image_1->EditValue = "";
            }

            // image_2
            $psacar_car->image_2->EditCustomAttributes = "";
            if (!ew_Empty($psacar_car->image_2->Upload->DbValue)) {
                $psacar_car->image_2->EditValue = $psacar_car->image_2->Upload->DbValue;
            } else {
                $psacar_car->image_2->EditValue = "";
            }

            // image_3
            $psacar_car->image_3->EditCustomAttributes = "";
            if (!ew_Empty($psacar_car->image_3->Upload->DbValue)) {
                $psacar_car->image_3->EditValue = $psacar_car->image_3->Upload->DbValue;
            } else {
                $psacar_car->image_3->EditValue = "";
            }

            // image_4
            $psacar_car->image_4->EditCustomAttributes = "";
            if (!ew_Empty($psacar_car->image_4->Upload->DbValue)) {
                $psacar_car->image_4->EditValue = $psacar_car->image_4->Upload->DbValue;
            } else {
                $psacar_car->image_4->EditValue = "";
            }

            // image_5
            $psacar_car->image_5->EditCustomAttributes = "";
            if (!ew_Empty($psacar_car->image_5->Upload->DbValue)) {
                $psacar_car->image_5->EditValue = $psacar_car->image_5->Upload->DbValue;
            } else {
                $psacar_car->image_5->EditValue = "";
            }

            // vehicle_id_number
            $psacar_car->vehicle_id_number->EditCustomAttributes = "";
            $psacar_car->vehicle_id_number->EditValue = ew_HtmlEncode($psacar_car->vehicle_id_number->CurrentValue);

            // negotiate
            $psacar_car->negotiate->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("1", "Yes/No");
            $psacar_car->negotiate->EditValue = $arwrk;

            // duration
            $psacar_car->duration->EditCustomAttributes = "";
            $psacar_car->duration->EditValue = ew_HtmlEncode($psacar_car->duration->CurrentValue);

            // create_date
            $psacar_car->create_date->EditCustomAttributes = "";
            $psacar_car->create_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->create_date->CurrentValue, 5));

            // end_date
            $psacar_car->end_date->EditCustomAttributes = "";
            $psacar_car->end_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->end_date->CurrentValue, 5));

            // status
            $psacar_car->status->EditCustomAttributes = "";
            $arwrk = array();
            $arwrk[] = array("0", "Pending");
            $arwrk[] = array("1", "Approved");
            $arwrk[] = array("2", "Deleted");
            array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
            $psacar_car->status->EditValue = $arwrk;

            // code
            $psacar_car->code->EditCustomAttributes = "";
            $psacar_car->code->EditValue = ew_HtmlEncode($psacar_car->code->CurrentValue);

            // created_date
            $psacar_car->created_date->EditCustomAttributes = "";
            $psacar_car->created_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->created_date->CurrentValue, 5));

            // modified_date
            $psacar_car->modified_date->EditCustomAttributes = "";
            $psacar_car->modified_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_car->modified_date->CurrentValue, 5));

            // Edit refer script
            // id

            $psacar_car->id->HrefValue = "";

            // dealer_id
            $psacar_car->dealer_id->HrefValue = "";

            // model_id
            $psacar_car->model_id->HrefValue = "";

            // type_id
            $psacar_car->type_id->HrefValue = "";

            // category_id
            $psacar_car->category_id->HrefValue = "";

            // description
            $psacar_car->description->HrefValue = "";

            // price
            $psacar_car->price->HrefValue = "";

            // quality
            $psacar_car->quality->HrefValue = "";

            // post_date
            $psacar_car->post_date->HrefValue = "";

            // expiration_date
            $psacar_car->expiration_date->HrefValue = "";

            // internal_color_id
            $psacar_car->internal_color_id->HrefValue = "";

            // external_color_id
            $psacar_car->external_color_id->HrefValue = "";

            // transmission
            $psacar_car->transmission->HrefValue = "";

            // legal
            $psacar_car->legal->HrefValue = "";

            // import_tax
            $psacar_car->import_tax->HrefValue = "";

            // drive_train
            $psacar_car->drive_train->HrefValue = "";

            // door_count
            $psacar_car->door_count->HrefValue = "";

            // fuel
            $psacar_car->fuel->HrefValue = "";

            // vat
            $psacar_car->vat->HrefValue = "";

            // destinations
            $psacar_car->destinations->HrefValue = "";

            // rent_type
            $psacar_car->rent_type->HrefValue = "";

            // vehicle_type_id
            $psacar_car->vehicle_type_id->HrefValue = "";

            // is_driver
            $psacar_car->is_driver->HrefValue = "";

            // image_1
            if (!ew_Empty($psacar_car->image_1->Upload->DbValue)) {
                $psacar_car->image_1->HrefValue = ew_UploadPathEx(FALSE, $psacar_car->image_1->UploadPath) . ((!empty($psacar_car->image_1->EditValue)) ? $psacar_car->image_1->EditValue : $psacar_car->image_1->CurrentValue);
                if ($psacar_car->Export <> "")
                    $psacar_car->image_1->HrefValue = ew_ConvertFullUrl($psacar_car->image_1->HrefValue);
            } else {
                $psacar_car->image_1->HrefValue = "";
            }

            // image_2
            if (!ew_Empty($psacar_car->image_2->Upload->DbValue)) {
                $psacar_car->image_2->HrefValue = ew_UploadPathEx(FALSE, $psacar_car->image_2->UploadPath) . ((!empty($psacar_car->image_2->EditValue)) ? $psacar_car->image_2->EditValue : $psacar_car->image_2->CurrentValue);
                if ($psacar_car->Export <> "")
                    $psacar_car->image_2->HrefValue = ew_ConvertFullUrl($psacar_car->image_2->HrefValue);
            } else {
                $psacar_car->image_2->HrefValue = "";
            }

            // image_3
            if (!ew_Empty($psacar_car->image_3->Upload->DbValue)) {
                $psacar_car->image_3->HrefValue = ew_UploadPathEx(FALSE, $psacar_car->image_3->UploadPath) . ((!empty($psacar_car->image_3->EditValue)) ? $psacar_car->image_3->EditValue : $psacar_car->image_3->CurrentValue);
                if ($psacar_car->Export <> "")
                    $psacar_car->image_3->HrefValue = ew_ConvertFullUrl($psacar_car->image_3->HrefValue);
            } else {
                $psacar_car->image_3->HrefValue = "";
            }

            // image_4
            if (!ew_Empty($psacar_car->image_4->Upload->DbValue)) {
                $psacar_car->image_4->HrefValue = ew_UploadPathEx(FALSE, $psacar_car->image_4->UploadPath) . ((!empty($psacar_car->image_4->EditValue)) ? $psacar_car->image_4->EditValue : $psacar_car->image_4->CurrentValue);
                if ($psacar_car->Export <> "")
                    $psacar_car->image_4->HrefValue = ew_ConvertFullUrl($psacar_car->image_4->HrefValue);
            } else {
                $psacar_car->image_4->HrefValue = "";
            }

            // image_5
            if (!ew_Empty($psacar_car->image_5->Upload->DbValue)) {
                $psacar_car->image_5->HrefValue = ew_UploadPathEx(FALSE, $psacar_car->image_5->UploadPath) . ((!empty($psacar_car->image_5->EditValue)) ? $psacar_car->image_5->EditValue : $psacar_car->image_5->CurrentValue);
                if ($psacar_car->Export <> "")
                    $psacar_car->image_5->HrefValue = ew_ConvertFullUrl($psacar_car->image_5->HrefValue);
            } else {
                $psacar_car->image_5->HrefValue = "";
            }

            // vehicle_id_number
            $psacar_car->vehicle_id_number->HrefValue = "";

            // negotiate
            $psacar_car->negotiate->HrefValue = "";

            // duration
            $psacar_car->duration->HrefValue = "";

            // create_date
            $psacar_car->create_date->HrefValue = "";

            // end_date
            $psacar_car->end_date->HrefValue = "";

            // status
            $psacar_car->status->HrefValue = "";

            // code
            $psacar_car->code->HrefValue = "";

            // created_date
            $psacar_car->created_date->HrefValue = "";

            // modified_date
            $psacar_car->modified_date->HrefValue = "";
            
            $psacar_car->id_image_1->EditValue = $psacar_car->id_image_1->CurrentValue;
            $psacar_car->id_image_2->EditValue = $psacar_car->id_image_2->CurrentValue;
            $psacar_car->id_image_3->EditValue = $psacar_car->id_image_3->CurrentValue;
            $psacar_car->id_image_4->EditValue = $psacar_car->id_image_4->CurrentValue;
            $psacar_car->id_image_5->EditValue = $psacar_car->id_image_5->CurrentValue;
        }

        // Call Row Rendered event
        if ($psacar_car->RowType <> EW_ROWTYPE_AGGREGATEINIT)
            $psacar_car->Row_Rendered();
    }

    // Validate form
    function ValidateForm() {
        global $Language, $gsFormError, $psacar_car;

        // Initialize form error message
        $gsFormError = "";
        if (!ew_CheckFileType($psacar_car->image->Upload->FileName)) {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $Language->Phrase("WrongFileType");
        }
        if ($psacar_car->image->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_car->image->Upload->FileSize > EW_MAX_FILE_SIZE) {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
        }

        // Check if validation required
        if (!EW_SERVER_VALIDATE)
            return ($gsFormError == "");
        if (!is_null($psacar_car->dealer_id->FormValue) && $psacar_car->dealer_id->FormValue == "") {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->dealer_id->FldCaption();
        }
        if (!is_null($psacar_car->model_id->FormValue) && $psacar_car->model_id->FormValue == "") {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->model_id->FldCaption();
        }
        if (!is_null($psacar_car->category_id->FormValue) && $psacar_car->category_id->FormValue == "") {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->category_id->FldCaption();
        }
        if (!ew_CheckNumber($psacar_car->price->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->price->FldErrMsg();
        }
        if (!ew_CheckInteger($psacar_car->quality->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->quality->FldErrMsg();
        }
        if (!ew_CheckDate($psacar_car->post_date->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->post_date->FldErrMsg();
        }
        if (!is_null($psacar_car->expiration_date->FormValue) && $psacar_car->expiration_date->FormValue == "") {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->expiration_date->FldCaption();
        }
        if (!ew_CheckDate($psacar_car->expiration_date->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->expiration_date->FldErrMsg();
        }
        if (!is_null($psacar_car->vehicle_id_number->FormValue) && $psacar_car->vehicle_id_number->FormValue == "") {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $Language->Phrase("EnterRequiredField") . " - " . $psacar_car->vehicle_id_number->FldCaption();
        }
        if (!ew_CheckInteger($psacar_car->duration->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->duration->FldErrMsg();
        }
        if (!ew_CheckDate($psacar_car->create_date->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->create_date->FldErrMsg();
        }
        if (!ew_CheckDate($psacar_car->end_date->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->end_date->FldErrMsg();
        }
        if (!ew_CheckDate($psacar_car->created_date->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->created_date->FldErrMsg();
        }
        if (!ew_CheckDate($psacar_car->modified_date->FormValue)) {
            if ($gsFormError <> "")
                $gsFormError .= "<br>";
            $gsFormError .= $psacar_car->modified_date->FldErrMsg();
        }

        // Return validate result
        $ValidateForm = ($gsFormError == "");

        // Call Form_CustomValidate event
        $sFormCustomError = "";
        $ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
        if ($sFormCustomError <> "") {
            $gsFormError .= ($gsFormError <> "") ? "<br>" : "";
            $gsFormError .= $sFormCustomError;
        }
        return $ValidateForm;
    }

    // Update record based on key values
    function EditRow() {
        global $conn, $Security, $Language, $psacar_car;
        $sFilter = $psacar_car->KeyFilter();
        $psacar_car->CurrentFilter = $sFilter;
        $sSql = $psacar_car->SQL();
        $conn->raiseErrorFn = 'ew_ErrorFn';
        $rs = $conn->Execute($sSql);
        $conn->raiseErrorFn = '';
        if ($rs === FALSE)
            return FALSE;
        if ($rs->EOF) {
            $EditRow = FALSE; // Update Failed
        } else {

            // Save old values
            $rsold = & $rs->fields;
            $rsnew = array();

            // dealer_id
            $psacar_car->dealer_id->SetDbValueDef($rsnew, $psacar_car->dealer_id->CurrentValue, 0, FALSE);

            // model_id
            $psacar_car->model_id->SetDbValueDef($rsnew, $psacar_car->model_id->CurrentValue, NULL, FALSE);

            // year                        
            $psacar_car->year->SetDbValueDef($rsnew, $psacar_car->year->CurrentValue, NULL, FALSE);

            // type_id
            $psacar_car->type_id->SetDbValueDef($rsnew, $psacar_car->type_id->CurrentValue, NULL, FALSE);

            // category_id
            $psacar_car->category_id->SetDbValueDef($rsnew, $psacar_car->category_id->CurrentValue, 0, FALSE);

            // description
            $psacar_car->description->SetDbValueDef($rsnew, $psacar_car->description->CurrentValue, NULL, FALSE);

            // price
            $psacar_car->price->SetDbValueDef($rsnew, $psacar_car->price->CurrentValue, NULL, FALSE);

            // quality
            $psacar_car->quality->SetDbValueDef($rsnew, $psacar_car->quality->CurrentValue, NULL, FALSE);

            // post_date
            $psacar_car->post_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->post_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // expiration_date
            $psacar_car->expiration_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->expiration_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // internal_color_id
            $psacar_car->internal_color_id->SetDbValueDef($rsnew, $psacar_car->internal_color_id->CurrentValue, NULL, FALSE);

            // external_color_id
            $psacar_car->external_color_id->SetDbValueDef($rsnew, $psacar_car->external_color_id->CurrentValue, NULL, FALSE);

            // transmission
            $psacar_car->transmission->SetDbValueDef($rsnew, $psacar_car->transmission->CurrentValue, NULL, FALSE);

            // legal
            $psacar_car->legal->SetDbValueDef($rsnew, $psacar_car->legal->CurrentValue, NULL, FALSE);

            // import_tax
            $psacar_car->import_tax->SetDbValueDef($rsnew, $psacar_car->import_tax->CurrentValue, NULL, FALSE);

            // drive_train
            $psacar_car->drive_train->SetDbValueDef($rsnew, $psacar_car->drive_train->CurrentValue, NULL, FALSE);

            // door_count
            $psacar_car->door_count->SetDbValueDef($rsnew, $psacar_car->door_count->CurrentValue, NULL, FALSE);

            // fuel
            $psacar_car->fuel->SetDbValueDef($rsnew, $psacar_car->fuel->CurrentValue, NULL, FALSE);

            // vat
            $psacar_car->vat->SetDbValueDef($rsnew, $psacar_car->vat->CurrentValue, NULL, FALSE);

            // destinations
            $psacar_car->destinations->SetDbValueDef($rsnew, $psacar_car->destinations->CurrentValue, NULL, FALSE);

            // rent_type
            $psacar_car->rent_type->SetDbValueDef($rsnew, $psacar_car->rent_type->CurrentValue, NULL, FALSE);

            // vehicle_type_id
            $psacar_car->vehicle_type_id->SetDbValueDef($rsnew, $psacar_car->vehicle_type_id->CurrentValue, NULL, FALSE);

            // is_driver
            $psacar_car->is_driver->SetDbValueDef($rsnew, $psacar_car->is_driver->CurrentValue, NULL, FALSE);

            // vehicle_id_number
            $psacar_car->vehicle_id_number->SetDbValueDef($rsnew, $psacar_car->vehicle_id_number->CurrentValue, "", FALSE);

            // negotiate
            $psacar_car->negotiate->SetDbValueDef($rsnew, $psacar_car->negotiate->CurrentValue, NULL, FALSE);

            // duration
            $psacar_car->duration->SetDbValueDef($rsnew, $psacar_car->duration->CurrentValue, NULL, FALSE);

            // create_date
            $psacar_car->create_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->create_date->CurrentValue, 5, FALSE), NULL);

            // end_date
            $psacar_car->end_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->end_date->CurrentValue, 5, FALSE), NULL);

            // status
            $psacar_car->status->SetDbValueDef($rsnew, $psacar_car->status->CurrentValue, NULL, FALSE);

            // code
            $psacar_car->code->SetDbValueDef($rsnew, $psacar_car->code->CurrentValue, NULL, FALSE);

            // created_date
            $psacar_car->created_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->created_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // modified_date
            $psacar_car->modified_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_car->modified_date->CurrentValue, 5, FALSE), ew_CurrentDate());

            // Call Row Updating event
            $bUpdateRow = $psacar_car->Row_Updating($rsold, $rsnew);
            if ($bUpdateRow) {
                $conn->raiseErrorFn = 'ew_ErrorFn';
                $EditRow = $conn->Execute($psacar_car->UpdateSQL($rsnew));
                $conn->raiseErrorFn = '';
            } else {
                if ($psacar_car->CancelMessage <> "") {
                    $this->setMessage($psacar_car->CancelMessage);
                    $psacar_car->CancelMessage = "";
                } else {
                    $this->setMessage($Language->Phrase("UpdateCancelled"));
                }
                $EditRow = FALSE;
            }
        }

        // Call Row_Updated event
        if ($EditRow) {
            $psacar_car->Row_Updated($rsold, $rsnew);                        
            $psacar_car->id->setDbValue($rs->fields('id'));  
            
            $id_image_filter = "";            
            if (($psacar_car->image_1->Upload->Action == "2" || $psacar_car->image_1->Upload->Action == "3")) {
                if ((strlen($id_image_filter) != 0) && (strlen($psacar_car->id_image_1->CurrentValue) != 0))
                    $id_image_filter .= ", ";
                
                $id_image_filter .= $psacar_car->id_image_1->CurrentValue;
            }
            
            if (($psacar_car->image_2->Upload->Action == "2" || $psacar_car->image_2->Upload->Action == "3")) {
                if ((strlen($id_image_filter) != 0) && (strlen($psacar_car->id_image_2->CurrentValue) != 0))
                    $id_image_filter .= ", ";
                
                $id_image_filter .= $psacar_car->id_image_2->CurrentValue;
            }

            if (($psacar_car->image_3->Upload->Action == "2" || $psacar_car->image_3->Upload->Action == "3")) {
                if ((strlen($id_image_filter) != 0) && (strlen($psacar_car->id_image_3->CurrentValue) != 0))
                    $id_image_filter .= ", ";
                
                $id_image_filter .= $psacar_car->id_image_3->CurrentValue;
            }

            if (($psacar_car->image_4->Upload->Action == "2" || $psacar_car->image_4->Upload->Action == "3")) {
                if ((strlen($id_image_filter) != 0) && (strlen($psacar_car->id_image_4->CurrentValue) != 0))
                    $id_image_filter .= ", ";
                
                $id_image_filter .= $psacar_car->id_image_4->CurrentValue;
            }
            
            if (($psacar_car->image_5->Upload->Action == "2" || $psacar_car->image_5->Upload->Action == "3")) {
                if ((strlen($id_image_filter) != 0) && (strlen($psacar_car->id_image_5->CurrentValue) != 0))
                    $id_image_filter .= ", ";
                
                $id_image_filter .= $psacar_car->id_image_5->CurrentValue;
            }

            //Delete existing image
            $DeleteRows = TRUE;
            if(strlen($id_image_filter) != 0) {
                $id_image_filter = "`id` in (" . $id_image_filter . ")";
                
                $psacar_car_image = new cpsacar_car_image();        
                $psacar_car_image->CurrentFilter = $id_image_filter;
                $sSql = $psacar_car_image->SQL();                                
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs_image = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';                
                
		if ($rs_image === FALSE) {                    
		} 
                elseif ($rs_image->EOF) {
                    $rs_image->Close();
		}
                
                if(!$rs_image->EOF) {
                    $conn->BeginTrans();

                    // Clone old rows
                    $rs_image_old = ($rs_image) ? $rs_image->GetRows() : array();
                    if ($rs_image)
                        $rs_image->Close();

                    // Call row deleting event
                    if ($DeleteRows) {
                        foreach ($rs_image_old as $row) {
                            $DeleteRows = $psacar_car_image->Row_Deleting($row);
                            if (!$DeleteRows) 
                                break;
                        }
                    }

                    if ($DeleteRows) {
                        $sKey = "";
                        foreach ($rs_image_old as $row) {
                            $sThisKey = "";
                            if ($sThisKey <> "") 
                                $sThisKey .= EW_COMPOSITE_KEY_SEPARATOR;

                            $sThisKey .= $row['id'];
                            $conn->raiseErrorFn = 'ew_ErrorFn';
                            $DeleteRows = $conn->Execute($psacar_car_image->DeleteSQL($row)); // Delete
                            $conn->raiseErrorFn = '';
                            if ($DeleteRows === FALSE)
                                break;

                            if ($sKey <> "") 
                                $sKey .= ", ";
                            $sKey .= $sThisKey;
                        }
                    } 
                    else {
                        // Set up error message
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } 
                        else {
                            $this->setMessage($Language->Phrase("DeleteCancelled"));
                        }
                    }

                    if ($DeleteRows) {
                        $conn->CommitTrans(); // Commit the changes
                    } 
                    else {
                        $conn->RollbackTrans(); // Rollback changes
                    }
                }
            }            
                
            if ($DeleteRows) {
                //Attach images to car
                // Image_1
                $rscar_image = array();
                $psacar_car->image_1->Upload->SaveToSession(); // Save file value to Session
                if (is_null($psacar_car->image_1->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_1->UploadPath), 
                        $psacar_car->image_1->Upload->FileName);
                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $psacar_car->id->CurrentValue, 0, FALSE);

                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_1->Upload->Value)) {
                            $psacar_car->image_1->Upload->SaveToFile(
                                $psacar_car->image_1->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';                            
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';                                
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }		                                

                // Image_2
                $rscar_image = array();
                $psacar_car->image_2->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_2->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_2->UploadPath), 
                        $psacar_car->image_2->Upload->FileName);

                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $psacar_car->id->CurrentValue, 0, FALSE);                

                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_2->Upload->Value)) {
                            $psacar_car->image_2->Upload->SaveToFile(
                                $psacar_car->image_2->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';                            
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }

                // Image_3
                $rscar_image = array();
                $psacar_car->image_3->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_3->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_3->UploadPath), 
                        $psacar_car->image_1->Upload->FileName);

                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $psacar_car->id->CurrentValue, 0, FALSE);                

                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_3->Upload->Value)) {
                            $psacar_car->image_3->Upload->SaveToFile(
                                $psacar_car->image_3->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';                            
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;                    

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }

                // Image_4
                $rscar_image = array();
                $psacar_car->image_4->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_4->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_4->UploadPath), 
                        $psacar_car->image_4->Upload->FileName);

                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $psacar_car->id->CurrentValue, 0, FALSE);                

                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_4->Upload->Value)) {
                            $psacar_car->image_4->Upload->SaveToFile(
                                $psacar_car->image_4->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }

                // Image_5
                $rscar_image = array();
                $psacar_car->image_5->Upload->SaveToSession(); // Save file value to Session                
                if (is_null($psacar_car->image_5->Upload->Value)) {
                    $rscar_image['image'] = NULL;
                }
                else {
                    $rscar_image['image'] = ew_UploadFileNameEx(
                        ew_UploadPathEx(
                            TRUE, 
                            $psacar_car->image_5->UploadPath), 
                        $psacar_car->image_5->Upload->FileName);

                    $psacar_car_image = new cpsacar_car_image();
                    $psacar_car_image->car_id->SetDbValueDef($rscar_image, $psacar_car->id->CurrentValue, 0, FALSE);                

                    // Call Row Inserting event
                    $bInsertRow = $psacar_car_image->Row_Inserting($rscar_image);
                    if ($bInsertRow) {
                        if (!ew_Empty($psacar_car->image_5->Upload->Value)) {
                            $psacar_car->image_5->Upload->SaveToFile(
                                $psacar_car->image_5->UploadPath, 
                                $rscar_image['image'], 
                                FALSE);
                        }
                        $conn->raiseErrorFn = 'ew_ErrorFn';
                        $AddRow = $conn->Execute($psacar_car_image->InsertSQL($rscar_image));
                        $conn->raiseErrorFn = '';
                    } 
                    else {
                        if ($psacar_car_image->CancelMessage <> "") {
                            $this->setMessage($psacar_car_image->CancelMessage);
                            $psacar_car_image->CancelMessage = "";
                        } else {
                            $this->setMessage($Language->Phrase("InsertCancelled"));
                        }
                        $AddRow = FALSE;
                    }
                    if ($AddRow) {
                        $psacar_car_image->id->setDbValue($conn->Insert_ID());
                        $rscar_image['id'] = $psacar_car_image->id->DbValue;

                        // Call Row Inserted event
                        $psacar_car_image->Row_Inserted($rscar_image);
                    }                    
                }                     
            }                     
        }
        
        $rs->Close();

        // image
        $psacar_car->image_1->Upload->RemoveFromSession(); // Remove file value from Session
        $psacar_car->image_2->Upload->RemoveFromSession(); // Remove file value from Session
        $psacar_car->image_3->Upload->RemoveFromSession(); // Remove file value from Session
        $psacar_car->image_4->Upload->RemoveFromSession(); // Remove file value from Session
        $psacar_car->image_5->Upload->RemoveFromSession(); // Remove file value from Session
        return $EditRow;
    }

    // Page Load event
    function Page_Load() {

        //echo "Page Load";
    }

    // Page Unload event
    function Page_Unload() {

        //echo "Page Unload";
    }

    // Page Redirecting event
    function Page_Redirecting(&$url) {

        // Example:
        //$url = "your URL";
    }

    // Message Showing event
    function Message_Showing(&$msg) {

        // Example:
        //$msg = "your new message";
    }

    // Form Custom Validate event
    function Form_CustomValidate(&$CustomError) {

        // Return error message in CustomError
        return TRUE;
    }

}
?>
